package com.qh.resourcehub.program.user.controller;

import cn.hutool.core.util.ObjectUtil;
import com.qh.resourcehub.program.dto.UserDto;
import com.qh.resourcehub.program.user.service.UserInfoService;
import com.qh.resourcehub.program.vo.UserTodoSummaryVO;
import com.qh.resourcehub.program.vo.UserVo;
import com.qh.resourcehub.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: Y6
 * @date: 2025/4/18 16:21
 */
@RestController
@RequestMapping("/userInfo")
//@Api(tags = "用户信息查询控制器")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;


    /*
     * @Description: 查询当前用户信息
     * @param null
     * @return
     * @Author: Y6
     * @Date: 2025/4/18 16:23
     */
    @PostMapping("/queryUserInfo")
    public ApiResponse queryUserInfo(@RequestBody UserDto userDto) {
        try {
            UserVo data = userInfoService.queryUserInfo(userDto);
            if (!ObjectUtil.isEmpty(data)){
                return ApiResponse.succeed(data);
            }else {
                return ApiResponse.succeedNoData();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("查询失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    /**
     * 查询当前部门领导列表
     * @param userDto
     * @return
     */
    @PostMapping("/queryUserLeaderInfo")
    public ApiResponse queryUserLeaderInfo(@RequestBody UserDto userDto) {
        try {
            List<UserVo> data = userInfoService.queryUserLeaderInfo(userDto);
            if (!ObjectUtil.isEmpty(data)){
                return ApiResponse.succeed(data);
            }else {
                return ApiResponse.succeedNoData();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("查询失败: " + e.getMessage()); // 返回详细错误信息
        }
    }
    /**
     * 查询信息中心相关科室值班员
     * @param
     * @return
     */
    @PostMapping("/queryUserSupportInfo")
    public ApiResponse queryUserSupportInfo(@RequestBody UserDto userDto) {
        try {
            List<UserVo> data = userInfoService.queryUserSupportInfo(userDto);
            if (!ObjectUtil.isEmpty(data)){
                return ApiResponse.succeed(data);
            }else {
                return ApiResponse.succeedNoData();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("查询失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    /**
     *
     * 当前用户代办数量列表
     * @return
     */
    @PostMapping("/queryUserRepresentativeNum")
    public ApiResponse queryUserRepresentativeNum(@RequestBody UserDto userDto) {
        try {
            UserTodoSummaryVO data = userInfoService.queryUserRepresentativeNum(userDto);
            if (!ObjectUtil.isEmpty(data)){
                return ApiResponse.succeed(data);
            }else {
                return ApiResponse.succeedNoData();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("查询失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    @PostMapping("/pushToMenuSystem")
    public ApiResponse pushToMenuSystem(@RequestBody UserDto userDto) {
        try {
            String result = userInfoService.pushToMenuSystem(userDto.getUserCode());
            if (result.startsWith("推送成功")) {
                return ApiResponse.succeed(result);
            } else {
                return ApiResponse.succeedRequestErr(result);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResponse.succeedRequestErr("推送异常: " + e.getMessage());
        }
    }

}
